import { Asset, SpriteFrame } from "cc";
import { BundleMgr } from "../../frame/mgr/BundleMgr";
import { ILoadingDep } from "./ILoading";


export class LoadingPublicDep implements ILoadingDep {
    loadedProgress: number = 0;
    readonly totalProgress: number = 1;

    private _arr: { res: string, tType: any }[] = [
        {
            res: "btn_blue", tType: SpriteFrame
        }
    ]
    bLoading: boolean;

    constructor(
        public bundleMgr: BundleMgr
    ) {

    }

    load(): void {
        // for (const { res, tType } of this._arr) {
        //     this.bundleMgr.public.load(res, tType, (err: any, data: Asset) => {
        //         this.loadedProgress++;
        //     })
        // }

        if (this.bLoading) {
            return;
        }
        this.bLoading = true;

        this.loadedProgress++;
    }
    checkCompleted(): boolean {
        const ret = this.loadedProgress >= this.totalProgress
        if (ret) {
            return true;
        }
        return false;
    }

    getProgress(): number {
        return this.loadedProgress / this.totalProgress;
    }

    getProgressDesc(): string {
        return "正在加载公共资源..." + this.getProgress();
    }


}